package com.yizhi.util;

public class ApiResult<T>{
    /**
     * 错误码，表示一种错误类型
     * 请求成功，状态码为200
     */
    private int code;

    /**
     * 对错误代码的详细解释
     */
    private String message;

    /**
     * 返回的结果包装在value中，value可以是单个对象
     */
    private T data;
    
    public static <T> ApiResult<T> success() {
        ApiResult<T> result = new ApiResult<T>();
        result.code = 200;
        return result;
    }
    
    public static <T> ApiResult<T> success(T object) {
        ApiResult<T> result = new ApiResult<T>();
        result.data = object;
        result.code = 200;
        result.message = "请求成功";
        return result;
    }
    
    public static <T> ApiResult<T> error(String message){
        ApiResult<T> result = new ApiResult<T>();
        result.message = message;
        return result;
    }
    
    public static <T> ApiResult<T> error(Integer code, String message) {
        ApiResult<T> result = new ApiResult<T>();
        result.message = message;
        result.code = code;
        return result;
    }
    
    public int getCode() {
        return code;
    }
    
    public void setCode(int code) {
        this.code = code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
}
